home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / chapter17 / infoabout.java < prev    next >
Text File  |  1995-12-31  |  784b  |  34 lines

  1.     /* info_about class */
  2.     class info_about {
  3.     
  4.     /* personable info */
  5.       String name;
  6.       int age;
  7.       int height;
  8.       int weight;
  9.     
  10.     /* constructor to set the name */
  11.     /*  weÆll assume other stats get set elsewhere/later */
  12.       public info_about(String S) { name = S; }
  13.  
  14.     /* hashCode method returns the first character */
  15.         public int hashCode() {
  16.         return (int)name.charAt(0);
  17.           }
  18.  
  19.     /* equals methods checks for match on first three characters */
  20.       public boolean equals(Object compare) {
  21.         info_about temp = (info_about)compare;
  22.     
  23.     /* check for first three letter match */
  24.         for (int g=0;g<3;++g) {
  25.         if (this.name.charAt(g) != temp.name.charAt(g)) 
  26.          return false;
  27.            }
  28.  
  29.     /* all matched, return true */
  30.       return true;
  31.       }
  32.     }
  33.  
  34.